function mountSyncExternalStore(subscribe, getSnapshot) {
	/* 创建一个 hooks */
	const hook = mountWorkInProgressHook()
	/* 创建快照 */
	let nextSnapshot = getSnapshot()
	/* 把快照记录下来 */
	hook.memoizedState = nextSnapshot
	/* 快照记录在 inst 属性上 */
	const inst = {
		value: nextSnapshot,
		getSnapshot,
	}
	hook.queue = inst
	/* 用一个 effect 来订阅状态，subscribeToStore 发起订阅 */
	mountEffect(subscribeToState.bind(null, fiber, inst, subscribe), [
		subscribe,
	])
	/* 用一个 useEffect 来监听组件 render ,只要组件渲染会调用 updateStoreInstance */
	pushEffect(
		HookHasEffect | HookPassive,
		updateStoreInstance.bind(null, fiber, inst, nextSnapshot, getSnapshot),
		undefined,
		null
	)
	return nextSnapshot
}
function checkIfSnapshotChanged(inst) {
	const latestGetSnapshot = inst.getSnapshot
	/* 取出上一次的快照信息 */
	const prevValue = inst.value
	try {
		/* 最新的快照信息 */
		const nextValue = latestGetSnapshot()
		/* 是否相等 */
		return !Object.is(prevValue, nextValue)
	} catch (err) {
		return true
	}
}
function forceStoreRerender(fiber) {
	scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp)
}
function subscribeToState(fiber, inst, subscribe) {
	const handleStoreChange = () => {
		/* 检查 state 是否发生变化 */
		if (checkIfSnapshotChanged(inst)) {
			/* 触发更新 */
			forceStoreRerender(fiber)
		}
	}
	/* 发起订阅 */
	return subscribe(handleStoreChange)
}
function updateStoreInstance(fiber, inst, nextSnapshot, getSnapshot) {
	inst.value = nextSnapshot
	inst.getSnapshot = getSnapshot
	/* 检查更新 */
	if (checkIfSnapshotChanged(inst)) {
		/* 强制更新 */
		forceStoreRerender(fiber)
	}
}
